package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.StrengthEntity;
import com.sgb.kjwl.model.entity.StrengthEntity2;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DetailWjjAdapter extends BaseRecycleAdapter<StrengthEntity2> {
    private TextView tv_category_item;
    private Map map;
    private String spec;
    private int index = -1;
    private ISelectWjj iSelectWjj;
    private boolean isClick = false;

    public DetailWjjAdapter(Context context, List<StrengthEntity2> datas) {
        super(context, R.layout.item_detail_wjj, datas);
        map = new HashMap();
    }

    @Override
    public void convert(ItemViewHolder holder, final StrengthEntity2 entity) {
        holder.setBinding(BR.viewModel, entity);
        tv_category_item = holder.getItem().findViewById(R.id.tv_category_item);
        if (entity.getSpec() == null && entity.getSpec().size() == 0) {
            tv_category_item.setCompoundDrawables(null, null, null, null);
        } else if (!entity.isHaveSpec()) {
            tv_category_item.setCompoundDrawables(null, null, null, null);
        }
//        if (map != null && map.size() != 0)

        if (isClick) {
            if (holder.getPosition() == index) {
                tv_category_item.setText(spec);
            }else {
                tv_category_item.setText(entity.getName());
            }
        } else {
            tv_category_item.setText(entity.getName());
        }

       /* tv_category_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iSelectWjj.onSelect(entity, holder.getPosition(), entity.isHaveSpec());
                if (holder.getPosition() == index) {
                    if (tv_category_item.isSelected() == false) {
                        tv_category_item.setSelected(true);
                    } else {
                        tv_category_item.setSelected(false);
                    }
                }
            }
        });*/

    }

    public void setArrName(String spec, int index, boolean isClick) {
        this.spec = spec;
        this.index = index;
        this.isClick = isClick;
        map.put(index, spec);
        notifyItemChanged(index);
    }

    public interface ISelectWjj {
        void onSelect(StrengthEntity2 entity, int position, boolean isHaveSpec);
    }

    public void OnSelectWjj(ISelectWjj iSelectWjj) {
        this.iSelectWjj = iSelectWjj;
    }
}
